package com.tinyengine.it.model.vo;

import cn.hutool.core.util.ObjUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
public class ApiDirectoryVo {

    private Integer id;
    private Integer appId;
    /**
     * 名称
     */
    @NotNull(message = "名称不能为空")
    private String name;

    @NotNull(message = "类型不能为空")
    @Schema(description = "1:目录（服务）  2：class  3:接口")
    private Integer type;

    @NotEmpty(message = "code不能为空")
    @NotNull(message = "code不能为空")
    @Schema(description = "用于服务名、接口controller名称")
    private String code;

    @Schema(description = "状态 ENUM(0-开发中, 1-已完成, 2-需修改, 3-已废弃)")
    private Integer status;

    /**
     * 上级
     */
    @NotNull(message = "父级ID不能为空")
    @Schema(description = "父级ID")
    private Integer parentId;

    /**
     * 描述
     */
    private String description;

    private List<ApiDirectoryVo> children;

    public void addChild(ApiDirectoryVo child) {
        if (ObjUtil.isNull(children)) {
            children = new ArrayList<>();
        }
        children.add(child);
    }

}
